<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />









  <meta name="baidu-site-verification" content="Q7ugSRSO7V" />







  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="最好是查看docker文档   查看docker信息（version、info）# 查看docker版本  docker version    # 显示docker系统的信息  docker info 对image的操作（search、pull、images、rmi、history）# 检索image  $docker search image_name    # 下载image  $dock">
<meta property="og:type" content="article">
<meta property="og:title" content="常用命令">
<meta property="og:url" content="http://yoursite.com/docker/常用命令/index.html">
<meta property="og:site_name" content="chimps">
<meta property="og:description" content="最好是查看docker文档   查看docker信息（version、info）# 查看docker版本  docker version    # 显示docker系统的信息  docker info 对image的操作（search、pull、images、rmi、history）# 检索image  $docker search image_name    # 下载image  $dock">
<meta property="og:updated_time" content="2017-04-23T14:55:17.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="常用命令">
<meta name="twitter:description" content="最好是查看docker文档   查看docker信息（version、info）# 查看docker版本  docker version    # 显示docker系统的信息  docker info 对image的操作（search、pull、images、rmi、history）# 检索image  $docker search image_name    # 下载image  $dock">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"hide","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":30},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/docker/常用命令/"/>





  <title> 常用命令 | chimps </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?dcb994042608bdb310eff950ba755ff1";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">chimps</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/docker/常用命令/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="chimps">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://sfault-avatar.b0.upaiyun.com/416/326/4163260007-58a1621e63a68_huge256">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="chimps">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                常用命令
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-04-23T22:54:40+08:00">
                2017-04-23
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/docker/" itemprop="url" rel="index">
                    <span itemprop="name">docker</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a class="cloud-tie-join-count" href="/docker/常用命令/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count join-count" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <hr>
<blockquote>
<p>最好是查看<a href="https://docker.github.io/engine/reference/commandline/" target="_blank" rel="external">docker文档</a></p>
</blockquote>
<hr>
<h1 id="查看docker信息（version、info）"><a href="#查看docker信息（version、info）" class="headerlink" title="查看docker信息（version、info）"></a>查看docker信息（version、info）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line"># 查看docker版本  </div><div class="line">docker version  </div><div class="line">  </div><div class="line"># 显示docker系统的信息  </div><div class="line">docker info</div></pre></td></tr></table></figure>
<h1 id="对image的操作（search、pull、images、rmi、history）"><a href="#对image的操作（search、pull、images、rmi、history）" class="headerlink" title="对image的操作（search、pull、images、rmi、history）"></a>对image的操作（search、pull、images、rmi、history）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line"># 检索image  </div><div class="line">$docker search image_name  </div><div class="line">  </div><div class="line"># 下载image  </div><div class="line">$docker pull image_name  </div><div class="line">  </div><div class="line"># 列出镜像列表; -a, --all=false Show all images; --no-trunc=false Don&apos;t truncate output; -q, --quiet=false Only show numeric IDs  </div><div class="line">$docker images  </div><div class="line">  </div><div class="line"># 删除一个或者多个镜像; -f, --force=false Force; --no-prune=false Do not delete untagged parents  </div><div class="line">$docker rmi image_name  </div><div class="line">  </div><div class="line"># 显示一个镜像的历史; --no-trunc=false Don&apos;t truncate output; -q, --quiet=false Only show numeric IDs  </div><div class="line">$docker history image_name</div></pre></td></tr></table></figure>
<h1 id="启动容器（run）"><a href="#启动容器（run）" class="headerlink" title="启动容器（run）"></a>启动容器（run）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line">$docker run image_name echo &quot;hello word&quot;  </div><div class="line">  </div><div class="line"># 交互式进入容器中  </div><div class="line">$docker run -i -t image_name /bin/bash  </div><div class="line">  </div><div class="line">  </div><div class="line"># 在容器中安装新的程序  </div><div class="line">$docker run image_name apt-get install -y app_name</div></pre></td></tr></table></figure>
<h1 id="查看容器（ps）"><a href="#查看容器（ps）" class="headerlink" title="查看容器（ps）"></a>查看容器（ps）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line"># 列出当前所有正在运行的container  </div><div class="line">$docker ps  </div><div class="line"># 列出所有的container  </div><div class="line">$docker ps -a  </div><div class="line"># 列出最近一次启动的container  </div><div class="line">$docker ps -l</div></pre></td></tr></table></figure>
<h1 id="保存对容器的修改（commit）"><a href="#保存对容器的修改（commit）" class="headerlink" title="保存对容器的修改（commit）"></a>保存对容器的修改（commit）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line"># 保存对容器的修改; -a, --author=&quot;&quot; Author; -m, --message=&quot;&quot; Commit message  </div><div class="line">$docker commit ID new_image_name</div></pre></td></tr></table></figure>
<h1 id="对容器的操作（rm、stop、start、kill、logs、diff、top、cp、restart、attach）"><a href="#对容器的操作（rm、stop、start、kill、logs、diff、top、cp、restart、attach）" class="headerlink" title="对容器的操作（rm、stop、start、kill、logs、diff、top、cp、restart、attach）"></a>对容器的操作（rm、stop、start、kill、logs、diff、top、cp、restart、attach）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line"># 删除所有容器  </div><div class="line">$docker rm `docker ps -a -q`  </div><div class="line">  </div><div class="line"># 删除单个容器; -f, --force=false; -l, --link=false Remove the specified link and not the underlying container; -v, --volumes=false Remove the volumes associated to the container  </div><div class="line">$docker rm Name/ID  </div><div class="line">  </div><div class="line"># 停止、启动、杀死一个容器  </div><div class="line">$docker stop Name/ID  </div><div class="line">$docker start Name/ID  </div><div class="line">$docker kill Name/ID  </div><div class="line">  </div><div class="line"># 从一个容器中取日志; -f, --follow=false Follow log output; -t, --timestamps=false Show timestamps  </div><div class="line">$docker logs Name/ID  </div><div class="line">  </div><div class="line"># 列出一个容器里面被改变的文件或者目录，list列表会显示出三种事件，A 增加的，D 删除的，C 被改变的  </div><div class="line">$docker diff Name/ID  </div><div class="line">  </div><div class="line"># 显示一个运行的容器里面的进程信息  </div><div class="line">$docker top Name/ID  </div><div class="line">  </div><div class="line"># 从容器里面拷贝文件/目录到本地一个路径  </div><div class="line">$docker cp Name:/container_path to_path  </div><div class="line">$docker cp ID:/container_path to_path  </div><div class="line">  </div><div class="line"># 重启一个正在运行的容器; -t, --time=10 Number of seconds to try to stop for before killing the container, Default=10  </div><div class="line">$docker restart Name/ID  </div><div class="line">  </div><div class="line"># 附加到一个运行的容器上面; --no-stdin=false Do not attach stdin; --sig-proxy=true Proxify all received signal to the process  </div><div class="line">$docker attach ID</div></pre></td></tr></table></figure>
<h1 id="保存和加载镜像（save、load）"><a href="#保存和加载镜像（save、load）" class="headerlink" title="保存和加载镜像（save、load）"></a>保存和加载镜像（save、load）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line">$docker save image_name -o file_path  </div><div class="line"># 加载一个tar包格式的镜像; -i, --input=&quot;&quot; Read from a tar archive file  </div><div class="line">$docker load -i file_path  </div><div class="line">  </div><div class="line"># 机器a  </div><div class="line">$docker save image_name &gt; /home/save.tar  </div><div class="line"># 使用scp将save.tar拷到机器b上，然后：  </div><div class="line">$docker load &lt; /home/save.tar</div></pre></td></tr></table></figure>
<h1 id="登录registry-server（login）"><a href="#登录registry-server（login）" class="headerlink" title="登录registry server（login）"></a>登录registry server（login）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line"># 登陆registry server; -e, --email=&quot;&quot; Email; -p, --password=&quot;&quot; Password; -u, --username=&quot;&quot; Username  </div><div class="line">$docker login</div></pre></td></tr></table></figure>
<h1 id="发布image（push）"><a href="#发布image（push）" class="headerlink" title="发布image（push）"></a>发布image（push）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line"># 发布docker镜像  </div><div class="line">$docker push new_image_name</div></pre></td></tr></table></figure>
<h1 id="根据Dockerfile-构建出一个容器（build）"><a href="#根据Dockerfile-构建出一个容器（build）" class="headerlink" title="根据Dockerfile 构建出一个容器（build）"></a>根据Dockerfile 构建出一个容器（build）</h1><figure class="highlight plain"><table><tr><td class="code"><pre><div class="line">#build  </div><div class="line">      --no-cache=false Do not use cache when building the image  </div><div class="line">      -q, --quiet=false Suppress the verbose output generated by the containers  </div><div class="line">      --rm=true Remove intermediate containers after a successful build  </div><div class="line">      -t, --tag=&quot;&quot; Repository name (and optionally a tag) to be applied to the resulting image in case of success  </div><div class="line">$docker build -t image_name Dockerfile_path</div></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/docker/docker-compose/" rel="next" title="docker-compose">
                <i class="fa fa-chevron-left"></i> docker-compose
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/digest/论成熟的男银/" rel="prev" title="论成熟的男银">
                论成熟的男银 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="cloud-tie-wrapper" class="cloud-tie-wrapper"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="https://sfault-avatar.b0.upaiyun.com/416/326/4163260007-58a1621e63a68_huge256"
               alt="chimps" />
          <p class="site-author-name" itemprop="name">chimps</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">59</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">12</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">19</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#查看docker信息（version、info）"><span class="nav-number">1.</span> <span class="nav-text">查看docker信息（version、info）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#对image的操作（search、pull、images、rmi、history）"><span class="nav-number">2.</span> <span class="nav-text">对image的操作（search、pull、images、rmi、history）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#启动容器（run）"><span class="nav-number">3.</span> <span class="nav-text">启动容器（run）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#查看容器（ps）"><span class="nav-number">4.</span> <span class="nav-text">查看容器（ps）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#保存对容器的修改（commit）"><span class="nav-number">5.</span> <span class="nav-text">保存对容器的修改（commit）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#对容器的操作（rm、stop、start、kill、logs、diff、top、cp、restart、attach）"><span class="nav-number">6.</span> <span class="nav-text">对容器的操作（rm、stop、start、kill、logs、diff、top、cp、restart、attach）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#保存和加载镜像（save、load）"><span class="nav-number">7.</span> <span class="nav-text">保存和加载镜像（save、load）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#登录registry-server（login）"><span class="nav-number">8.</span> <span class="nav-text">登录registry server（login）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#发布image（push）"><span class="nav-number">9.</span> <span class="nav-text">发布image（push）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#根据Dockerfile-构建出一个容器（build）"><span class="nav-number">10.</span> <span class="nav-text">根据Dockerfile 构建出一个容器（build）</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">chimps</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  








  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  


  




	





  
    
    <script>
      var cloudTieConfig = {
        url: document.location.href, 
        sourceId: "",
        productKey: "48bb30d8783d4b38ba0c95e0283238ca",
        target: "cloud-tie-wrapper"
      };
    </script>
    <script src="https://img1.ws.126.net/f2e/tie/yun/sdk/loader.js"></script>
  










  





  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  

</body>
</html>
